package com.lzy.cloud.base.config;

import com.lzy.framework.core.utils.MD5Utils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * @Author: 19516
 * @Despriction:
 * @Date: 2018-06-04 16:22
 */
@Configuration
@Data
@PropertySource("classpath:props/config.properties")
@Slf4j
public class SysUserAdminConfig {

    /**
     * 默认密码
     */
    @Value("${default.password}")
    private String defaultPassword;

    /**
     * token超时时间
     */
    @Value("${token.timeout}")
    private Integer tokenTimeout;

    /**
     * 盐值
     */
    @Value("${salt}")
    private String salt;

    /**
     * 默认密码md5值
     */
    private String defaultPasswordMd5;

    @Bean
    public SysUserAdminConfig genConfig() {
        this.setDefaultPasswordMd5(defaultPasswordMd5());
        return this;
    }

    private String defaultPasswordMd5() {
        if (this.defaultPassword == null) {
            log.error("未设置默认密码");
            return null;
        } else {
            return MD5Utils.MD5(this.defaultPassword);
        }
    }

}
